package com.edu.springboot.controller;


import com.edu.springboot.domain.Users;
import lombok.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController

@RequestMapping("/test")
//springboot的跨域处理
@CrossOrigin(value = "*",maxAge = 3600)
public class TestController {

    //读取配置文件中指定属性的值完成bean的属性注入
//    @Value(8090)
    private Integer port;

//    @Value("${serve.swedu}")
    private String edu;

    @GetMapping("/demo1")
    public String demo1() {
        System.out.println("demo1.....端口号："+this.port+"学院名称："+this.edu);
        return "demo1...端口号："+this.port;
    }

    @GetMapping("/demo2")
    public String demo2() {
        return "demo2...";
    }

    @GetMapping("/selectbyid")
    public Users selectById(Integer id){
        Users users=new Users(id,"admin","123abc",18);
        return users;
    }

    @GetMapping("/selectbyid2/{id}")
    public Users selectById2(@PathVariable("id") Integer id){
        Users users=new Users(id,"admin","123abc",18);
        return users;
    }

    //@RequestBody把json对象转成java对象
    @PostMapping("/insert")
    public String insert(@RequestBody Users users){
        System.out.println(users);
        return "insert-success";
    }

    @PostMapping("/inserts")
    public String inserts(@RequestBody List <Users> list){
        System.out.println(list);
        return "inserts-success";
    }
}
